﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfApplication1.RssFeedService;


namespace WPFClient
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public utils u;
        private rssFeed rssFeedWin;

        public MainWindow()
        {
            u = new utils();
            InitializeComponent();
            u._win = this;
            rssFeedWin = new rssFeed(u);
        }

        private void rfs_startSessionCompleted(Object sender, startSessionCompletedEventArgs e)
        {
            if (e.Result.id == 0)
                label1.Content = "Connexion failed";
            else
            {
                u.setSession(e.Result);
                label1.Content = "Client numero " + u.getSession().id + "; status = " + u.getSession().status;
                label2.Content = "Version du client : " + u.getSession().version;
                rssFeedWin.Visibility = System.Windows.Visibility.Visible;
                WPFClient.Visibility = System.Windows.Visibility.Hidden;
                rssFeedWin.label1.Content = "Client numero " + u.getSession().id;
                rssFeedWin.label2.Content = "Status : " + u.getSession().status;
            }
            return;
        }
        
        private void connect_Click(object sender, RoutedEventArgs e)
        {
            if (tblogin.Text == "" || tbpassword.Text == "")
            {
                label1.Content = "Login ou password incorrect";
                return;
            }
            label1.Content = "Chargement...";
            String login = tblogin.Text;
            String password = tbpassword.Text;
            u.setRfs(new RssFeedServiceClient("BasicHttpBinding_IRssFeedService"));
            u.getRfs().startSessionCompleted += new EventHandler<startSessionCompletedEventArgs>(rfs_startSessionCompleted);
            u.getRfs().startSessionAsync(tblogin.Text, tbpassword.Text, ServiceDevice.WPF);
        }


    }
}
